cmake_minimum_required(VERSION 3.16)

project(sensor VERSION 0.1 LANGUAGES CXX)

# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 查找 Qt6 组件
find_package(Qt6 REQUIRED COMPONENTS Quick SerialPort)

# 进行 Qt 标准项目设置
qt_standard_project_setup(REQUIRES 6.5)

# 显式列出头文件
set(HEADER_FILES
    "${CMAKE_CURRENT_SOURCE_DIR}/include/SensorFactor.h"
    "${CMAKE_CURRENT_SOURCE_DIR}/include/compass.h"
    "${CMAKE_CURRENT_SOURCE_DIR}/include/depth.h"
    "${CMAKE_CURRENT_SOURCE_DIR}/include/device.h"
    "${CMAKE_CURRENT_SOURCE_DIR}/include/manager.h"
    "${CMAKE_CURRENT_SOURCE_DIR}/include/posture.h"
    "${CMAKE_CURRENT_SOURCE_DIR}/include/sensorfactory.h"
    "${CMAKE_CURRENT_SOURCE_DIR}/include/sensorreleasetask.h"
)

# 显式列出源文件
set(SOURCE_FILES
    "${CMAKE_CURRENT_SOURCE_DIR}/source/compass.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/source/depth.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/source/device.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/source/manager.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/source/posture.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/source/sensorfactory.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/source/sensorreleasetask.cpp"
)

# 列出 QML 文件
set(QML_FILES
    rec.qml
    sensor.qml
    back.qml
    SensorInfo.qml
    Main.qml
)

# 列出资源文件
set(RESOURCE_FILES
    config.ini
    sleep.svg
)

# 添加可执行文件
qt_add_executable(appsensor
    main.cpp
    ${HEADER_FILES}
    ${SOURCE_FILES}
)

# 添加 QML 模块
qt_add_qml_module(appsensor
    URI sensor
    VERSION 1.0
    QML_FILES ${QML_FILES}
    SOURCES ${HEADER_FILES} ${SOURCE_FILES}
    RESOURCES ${RESOURCE_FILES}
)

# 设置目标属性
set_target_properties(appsensor PROPERTIES
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

# 链接 Qt6 库
target_link_libraries(appsensor
    PRIVATE Qt6::Quick Qt6::SerialPort
)

# 包含头文件目录
target_include_directories(appsensor PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include")

# 安装目标
include(GNUInstallDirs)
install(TARGETS appsensor
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
